const globalVersion = require('../../../public/version/index.js')
let settings = global.electronSettings || null
if (settings) {
    //
} else if (typeof window !== 'undefined' && window.require) {
    settings = window.require('electron-settings')
} else {
    settings = require('electron-settings')
}

// 项目名称 + 环境
let settingsName = `${globalVersion.name}.${globalVersion.versionType}`

/**
 * 对象里面是否有这个属性
 * @param {String} obj
 * @param {String} key 属性
 * @return {Boolean}
 */
function hasKey(obj, key) {
    return settings.has(`${settingsName}.${obj}.${key}`)
}

/**
 * 对象里面获取这个属性的值
 * @param {String} obj
 * @param {String} key 属性
 */
function getVal(obj, key) {
    return settings.get(`${settingsName}.${obj}.${key}`)
}

/**
 * 设置对象里面的属性的值
 * @param {String} obj
 * @param {String} key 属性
 * @param {String} val 值
 */
function setVal(obj, key, val) {
    settings.set(`${settingsName}.${obj}.${key}`, val)
}

module.exports = {
    hasKey,
    getVal,
    setVal
}
